package com.xxxx.spark.job

import org.apache.spark.{SparkConf, SparkContext}

object SecondSort {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("uv")
    val sc = new SparkContext(conf)
    val file = sc.textFile("data/secondSort.txt")
    file.map(line => {
      val strings = line.split(" ")
      var bean = SecondSort(strings(0).toInt,strings(1).toInt)
      (bean,line)
    })
      .sortByKey()
      .foreach(e => e._2)
  }
}

case class SecondSort(first: Int, second: Int) extends Serializable with Ordered[SecondSort]{
  override def compare(that: SecondSort): Int = {
    if(first == that.first)
      second - that.second
    else
      first - that.first
  }
}
